import sherpa_ncnn
import os

from get_config import config

audio_config = config["audio"]
recognition_config = config["recognition"]
# 设置模型文件路径
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
MODEL=recognition_config["model"]
MODEL_DIR = os.path.join(BASE_DIR, "sherpa_ncnn",MODEL)

TARGET_RATE = audio_config["target_rate"]
recognizer = sherpa_ncnn.Recognizer(
        tokens=os.path.join(MODEL_DIR, "tokens.txt"),
        encoder_param=os.path.join(MODEL_DIR, "encoder_jit_trace-pnnx.ncnn.param"),
        encoder_bin=os.path.join(MODEL_DIR, "encoder_jit_trace-pnnx.ncnn.bin"),
        decoder_param=os.path.join(MODEL_DIR, "decoder_jit_trace-pnnx.ncnn.param"),
        decoder_bin=os.path.join(MODEL_DIR, "decoder_jit_trace-pnnx.ncnn.bin"),
        joiner_param=os.path.join(MODEL_DIR, "joiner_jit_trace-pnnx.ncnn.param"),
        joiner_bin=os.path.join(MODEL_DIR, "joiner_jit_trace-pnnx.ncnn.bin"),
        num_threads=4,
        num_active_paths=4,
        model_sample_rate=TARGET_RATE,
        hotwords_score=100.0,
        enable_endpoint_detection=True,
        rule1_min_trailing_silence=2.5,
        rule2_min_trailing_silence=1.5,
        rule3_min_utterance_length=30,
        decoding_method='modified_beam_search',
        hotwords_file=os.path.join(MODEL_DIR, "hot.text")
)